package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import model.Set;

/**
 * Form window
 * @author Adrien Ledeul
 * @version 0.1
 */
public class FormWindow extends JFrame implements ActionListener
{
	private static final long serialVersionUID = 1L;
	
	private JMenu m1;
	private JMenuItem mi1;
	private JMenuItem mi2;
	private JMenuItem mi3;
	private JMenuItem mi4;
	private FormPanel pane;
	
	private Set set;
	
	/**
	 * Constructors
	 * 
	 */
	public FormWindow(Set set)
	{
		super();
		this.set = set;
		this.build();
	}
	
	/**
	 * Getters & Setters
	 * 
	 */
	public Set getSet() 
	{
		return set;
	}
	
	
	/**
	 * Build the window
	 */
	private void build()
	{		
		this.setTitle("Alarm Generator"); 
		this.setSize(250,270); 
		this.setLocationRelativeTo(null); 
		this.setResizable(false); 
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
		this.setContentPane(this.buildContentPane());
		
		//Menu
		JMenuBar mb = new JMenuBar();
		m1 = new JMenu("Building");
		mi1 = new JMenuItem("Polytech");
		mi2 = new JMenuItem("IMUS");
		mi3 = new JMenuItem("IUT");
		mi4 = new JMenuItem("Home");
		m1.add(mi1);
		m1.add(mi2);
		m1.add(mi3);
		m1.add(mi4);
		
		mb.add(m1);
		this.setJMenuBar(mb);
		mi1.addActionListener(this);
		mi2.addActionListener(this);
		mi3.addActionListener(this);
		mi4.addActionListener(this);
	}
	
	/**
	 * Build the panel for the window
	 */
	private JPanel buildContentPane()
	{
		pane = new FormPanel(this);
		return pane;
	}

	@Override
	public void actionPerformed(ActionEvent e) 
	{
        if (e.getSource() == mi1 || e.getSource() == mi2 || e.getSource() == mi3 || e.getSource() == mi4)
        	pane.getTitle().setText(((JMenuItem) e.getSource()).getText());

	}
}